package com.demo.business.label;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 标签表
 * @create: 2022-02-25 23:30:07
 **/
@Service("label")
@Slf4j
public class LabelService{

    @Resource
    LabelDao labelDao;

    /**
     * 添加标签表,获取lLabelId数据
     *
     * @param cdoRequest - lLabelId:服务类别id
     *                   - slabelName:标签名称
     *                   - sThumbnail:服务类别缩略图
     *                   - iThumbnailStatus:标签缩略图状态1.上架2.下架
     *                   - sSynopsis:标签简介
     *                   - dCreateTime:创建时间
     *                   - dUpdateTime:修改时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return addLabel(CDO cdoRequest) {
        labelDao.addLabel(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("lLabelId")) {
            cdoResult.set("lLabelId", cdoRequest.get("lLabelId"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据lLabelId，更新标签表数据
     *
     * @param cdoRequest - lLabelId:服务类别id
     *                   - slabelName:标签名称
     *                   - sThumbnail:服务类别缩略图
     *                   - iThumbnailStatus:标签缩略图状态1.上架2.下架
     *                   - sSynopsis:标签简介
     *                   - dCreateTime:创建时间
     *                   - dUpdateTime:修改时间
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return updateLabelById(CDO cdoRequest) {
        int affectedRows = labelDao.updateLabelById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据lLabelId，删除标签表数据
     *
     * @param cdoRequest - lLabelId:服务类别id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    //@OpenApi
    public Return deleteLabelById(CDO cdoRequest){
        int affectedRows = labelDao.deleteLabelById(cdoRequest.getLong("lLabelId"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除标签表数据
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    //@OpenApi
    public Return deleteLabel(CDO cdoRequest) {
        int affectedRows = labelDao.deleteLabel(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取标签表数据
     *
     * @param cdoRequest - lLabelId:服务类别id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return getLabelById(CDO cdoRequest) {
        CDO cdoMapperResult = labelDao.getLabelById(cdoRequest.getLong("lLabelId"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取标签表数据
     *
     * @param cdoRequest - lLabelId:服务类别id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return getLabel(CDO cdoRequest) {
        CDO cdoMapperResult = labelDao.getLabel(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取标签表数据列表
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return getLabelList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = labelDao.getLabelList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = labelDao.getLabelListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取标签表数据列表
     *
     * @param cdoRequest - lLabelId:服务类别id
     * @return
     * @author 
     * @create: 2022-02-25 23:30:07
     */
    @OpenApi
    public Return getLabelListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = labelDao.getLabelListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = labelDao.getLabelListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
